﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Security.Cryptography;
using System.Text;

namespace BarcodeHandlerForms
{
    public class Utils
    {
        public static Configuration GetConfiguration()
        {
            ExeConfigurationFileMap configMap = new ExeConfigurationFileMap();
            configMap.ExeConfigFilename = string.Format("{0}/settings.config", AppDomain.CurrentDomain.BaseDirectory);
            Configuration config = ConfigurationManager.OpenMappedExeConfiguration(configMap, ConfigurationUserLevel.None);
            return config;
        }

        public static string GetSHA1Str(string enStr)
        {
            SHA1 sha1 = SHA1.Create();
            byte[] originalPwd = Encoding.UTF8.GetBytes(enStr);
            byte[] encryPwd = sha1.ComputeHash(originalPwd);
            return string.Join("", encryPwd.Select(b => string.Format("{0:x2}", b)).ToArray()).ToUpper();
        }
    }
}
